﻿using MediatR;
using W.Product.API.Appliaction.Command.ProductCommand;
using W.Product.Domain.Product;
using W.Product.Repository.Interface;

namespace W.Product.API.Appliaction.CommandHandler.ProductCommandHandler
{
    public class ProductIsDelCommandHandler : IRequestHandler<ProductIsDelCommand, int>
    {
        private readonly  IProductRepository _productRepository;

        public ProductIsDelCommandHandler(IProductRepository productRepository)
        {
            _productRepository = productRepository;
        }
        public async Task<int> Handle(ProductIsDelCommand request, CancellationToken cancellationToken)
        {
            var list = (await _productRepository.GetAll()).Where(x => request.ProductId.Contains(x.ProductId)).ToList();
            list.ForEach(x =>
            {
                x.IsDelete = true;
                x.DeleteName = "admin";
                x.DeleteTime = DateTime.Now;
            });
           return await _productRepository.IsUpdate(list);
        }
    }
}
